package com.ryan.quartz.temp.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Rayn on 2017/10/17.
 * @email liuwei412552703@163.com.
 */
public class WeatherData implements Subject {

    private List<Observer> observers;

    private float temperature;
    private float humidity;
    private float pressure;

    public WeatherData() {
        observers = new ArrayList<Observer>();
    }

    /**
     * 通知所有观察者
     */
    @Override
    public void notifyObservers() {
        for (Observer observer : observers) {
            observer.update(temperature, humidity, pressure);
        }
    }

    /**
     * 注册监听者
     *
     * @param observer
     */
    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    /**
     * 移除监听者
     *
     * @param observer
     */
    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    /**
     *
     */
    public void changeMeasurements(){
        notifyObservers();
    }

    /**
     *
     * @param tempreature
     * @param humidity
     * @param pressure
     */
    public void changeMeasurements(float tempreature, float humidity, float pressure){
        this.temperature = tempreature;
        this.humidity = humidity;
        this.pressure = pressure;

        changeMeasurements();
    }
}
